package problem646;

//646.最长对数链
//https://leetcode.cn/problems/maximum-length-of-pair-chain/

import java.util.Arrays;

class Solution {
    public int findLongestChain(int[][] pairs) {
        Arrays.sort(pairs, (a, b)->a[0]-b[0]);
        int n = pairs.length;
        int[] dp = new int[n];
        for(int i = 0; i<n; i++) {
            dp[i] = 1;
        }

        int ret = dp[0];
        for(int i = 1; i<n; i++) {
            for(int j = i-1; j>=0; j--) {
                if(pairs[j][1] < pairs[i][0]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
            ret = Math.max(ret, dp[i]);
            System.out.println(dp[i]);
        }
        return ret;
    }
}

/*
先根据第一个值进行排序
dp[i]:以第i个数对为结尾的最长数对链的长度

*/